package com.youlu.campus.admin.ca.controller;

import com.youlu.campus.common.base.RestResult;
import com.youlu.campus.common.base.RestResultBuilder;
import com.youlu.campus.entity.VO.req.CreateCertificateActivityConfigReq;
import com.youlu.campus.entity.VO.req.QueryCertActivityConfigReq;
import com.youlu.campus.service.ca.impl.CertificateActivityConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CertificateActivityConfigController {

    @Autowired
    private CertificateActivityConfigService certificateActivityConfigService;

    @PostMapping("/certificate/add-edit")
    public RestResult saveOrUpdate(@RequestBody @Validated CreateCertificateActivityConfigReq createCertificate,
                                   BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return RestResultBuilder.builder().failure(bindingResult.getFieldError().getDefaultMessage()).build();
        }
        certificateActivityConfigService.saveOrUpdate(createCertificate);
        return RestResultBuilder.builder().success().build();
    }

    @PostMapping("/certificate/list")
    public RestResult list(@RequestBody QueryCertActivityConfigReq queryCertActivityConfigReq){
        return RestResultBuilder.builder().data(certificateActivityConfigService.list(queryCertActivityConfigReq)).success().build();
    }

    @PostMapping("/certificate/detail")
    public RestResult detail(@RequestParam("id") String id){
        return RestResultBuilder.builder().data(certificateActivityConfigService.detail(id)).success().build();
    }

}
